#include "imagesavethread.h"
#include <opencv2/opencv.hpp>
#include <QDebug>

ImageSaveThread::ImageSaveThread(const cv::Mat& image, const QString& filePath, QObject* parent)
    : QThread(parent), m_image(image), m_filePath(filePath) {
}

ImageSaveThread::~ImageSaveThread() {
    // 确保线程结束后资源被正确释放
    if (isRunning()) {
        quit();
        wait();
    }
}

void ImageSaveThread::run() {
    // 将图像保存到指定路径
    if(m_image.empty())
    {

    }
    std::string path = m_filePath.toStdString();
    bool success = cv::imwrite(path, m_image);

    // 发射信号通知主线程
    //emit imageSaved(success);

    if (success) {
        qDebug() << "Image saved successfully to" << m_filePath;
    } else {
        qDebug() << "Failed to save image to" << m_filePath;
    }
}
